package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.RuoyiStudent;
import com.ruoyi.service.IRuoyiStudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生Controller
 *
 * @author ruoyi
 * @date 2023-07-31
 */
@RestController
@RequestMapping("/teaching-function/student")
public class RuoyiStudentController extends BaseController {
    @Autowired
    private IRuoyiStudentService ruoyiStudentService;

    /**
     * 查询学生列表
     */
    @PreAuthorize("@ss.hasPermi('teaching-function:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(RuoyiStudent ruoyiStudent) {
        startPage();
        List<RuoyiStudent> list = ruoyiStudentService.selectRuoyiStudentList(ruoyiStudent);
        return getDataTable(list);
    }

    /**
     * 导出学生列表
     */
    @PreAuthorize("@ss.hasPermi('teaching-function:student:export')")
    @Log(title = "学生" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RuoyiStudent ruoyiStudent) {
        List<RuoyiStudent> list = ruoyiStudentService.selectRuoyiStudentList(ruoyiStudent);
        ExcelUtil<RuoyiStudent> util = new ExcelUtil<RuoyiStudent>(RuoyiStudent.class);
        util.exportExcel(response, list, "学生数据");
    }

    /**
     * 获取学生详细信息
     */
    @PreAuthorize("@ss.hasPermi('teaching-function:student:query')")
    @GetMapping(value = "/{stuId}")
    public AjaxResult getInfo(@PathVariable("stuId") Long stuId) {
        return success(ruoyiStudentService.selectRuoyiStudentByStuId(stuId));
    }

    /**
     * 新增学生
     */
    @PreAuthorize("@ss.hasPermi('teaching-function:student:add')")
    @Log(title = "学生" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RuoyiStudent ruoyiStudent) {
        return toAjax(ruoyiStudentService.insertRuoyiStudent(ruoyiStudent));
    }

    /**
     * 修改学生
     */
    @PreAuthorize("@ss.hasPermi('teaching-function:student:edit')")
    @Log(title = "学生" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RuoyiStudent ruoyiStudent) {
        return toAjax(ruoyiStudentService.updateRuoyiStudent(ruoyiStudent));
    }

    /**
     * 删除学生
     */
    @PreAuthorize("@ss.hasPermi('teaching-function:student:remove')")
    @Log(title = "学生" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{stuIds}")
    public AjaxResult remove(@PathVariable Long[] stuIds) {
        return toAjax(ruoyiStudentService.deleteRuoyiStudentByStuIds(stuIds));
    }
}
